import request from "@/utils/request";
const _BASE_URL = "/biz/param/model";

// 参数模型类别查询参数
export interface ParamModelCategoryQuery extends PageQuery {
  keywords?: string;
}

// 参数模型查询参数
export interface ParamModelPageQuery extends PageQuery {
  keywords?: string;
  categoryId?: string;
}

// 参数模型类别
export interface ParamModelCategoryVO {
  id: string;
  name: string;
  parentId: string;
  children?: ParamModelCategoryVO[];
  sort: number;
  createTime: Date;
  updateTime: Date;
  createUserId: string;
  updateUserId: string;
}

// 参数模型类别表单
export interface ParamModelCategoryForm {
  id?: string;
  name?: string;
  parentId?: string;
  sort?: number;
}

// 参数模型
export interface ParamModelVO {
  id: string;
  categoryId: string;
  name: string;
  type: string;
  data: string;
  sort: number;
  createTime: Date;
  updateTime: Date;
  createUserId: string;
  updateUserId: string;
}

// 参数模型表单
export interface ParamModelForm {
  /*描述 */
  description?: string;

  /*名称 */
  name?: string;

  /*主键 */
  id?: string;

  /*内容 */
  content?: string;

  /*序号 */
  sort?: number;

  /*标识 */
  code?: string;

  /*分类 */
  categoryId?: string;
}

// API 方法
const ParamModelAPI = {
  // 获取参数模型类别分页列表
  getCategoryPage(queryParams: any) {
    return request<any, ParamModelCategoryVO[]>({
      url: `${_BASE_URL}/category/pages`,
      method: "get",
      params: queryParams,
    });
  },

  // 保存参数模型类别
  saveCategory(data: ParamModelCategoryForm) {
    return request<any, ParamModelCategoryVO>({
      url: `${_BASE_URL}/category/save`,
      method: "post",
      data: data,
    });
  },

  // 删除参数模型类别
  deleteCategoryByIds(ids: string) {
    return request({
      url: `${_BASE_URL}/category/${ids}`,
      method: "delete",
    });
  },

  // 获取参数模型分页列表
  getModelPage(queryParams: ParamModelPageQuery) {
    return request<any, PageResult<ParamModelVO>>({
      url: `${_BASE_URL}/pages`,
      method: "get",
      params: queryParams,
    });
  },

  // 保存参数模型
  saveModel(data: any) {
    return request<any, ParamModelVO>({
      url: `${_BASE_URL}/save`,
      method: "post",
      data: data,
    });
  },

  // 删除参数模型
  deleteModelByIds(ids: string) {
    return request({
      url: `${_BASE_URL}/${ids}`,
      method: "delete",
    });
  },
};
export default ParamModelAPI;

export interface ParamDefinition {
  identifier: string;
  name: string;
  accessMode: 'r' | 'rw';
  required: boolean;
  dataType:DataTypeDefinition
  defaultValue: string;
}

export interface DataTypeDefinition {
	type: "int" | "float" | "double" | "text" | "date" | "bool" | "enum" | "struct" | "array";
	specs?:any
}

export interface NumberSpecsDefinition { 
	min?: number;
	max?: number;
	unit?: string;
	step?: number;
}

export interface BoolSpecsDefinition {
	'0'?: string;
	'1'?: string;
}

export interface EnumSpecsDefinition {
	[key: string]: any;
}

export interface TextSpecsDefinition {
	length?: number;
}

export interface ArraySpecsDefinition {
	size?: number;
	item?: ArraySpecsItemDefinition;
}

export interface ArraySpecsItemDefinition {
	type?: string;
	item?: ParamDefinition;
}




